package com.zhoug.permissiondemo2;

import android.Manifest;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;

import com.zhoug.permission2.ZPermissions;

import java.util.ArrayList;

public class MainActivity extends MyBaseActivity {
    private Button mBtnRequestPermission;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_main;
    }

    @Override
    protected void findViews() {
        mBtnRequestPermission=findViewById(R.id.btn_reqeustPermission);

    }

    @Override
    protected void onCreate1(Bundle savedInstanceState) {
        mBtnRequestPermission.setOnClickListener(v->{
            ZPermissions.with(this)
                    .setPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE,
                            Manifest.permission.READ_EXTERNAL_STORAGE,
                            Manifest.permission.CAMERA

                    )
                    .setShowDescription(true)
                    .setDescription("请求需要权限")
                    .setCallback(new ZPermissions.Callback() {
                        @Override
                        public void onRequestPermissionsResult(boolean success, ArrayList<String> granted, ArrayList<String> denied) {
                            if(success){
                                Toast.makeText(MainActivity.this, "权限请求成功", Toast.LENGTH_SHORT).show();
                            }else{
                                Toast.makeText(MainActivity.this, "权限请求失败", Toast.LENGTH_SHORT).show();
                            }
                        }
                    })
                    .request();
        });
    }
}